package org.car.word.wx.api.PrototypePattern.service;

import java.util.Hashtable;

public class ShapeCache {

	private static Hashtable<String, Shape>  shapeMap = new Hashtable<String,Shape>();
	
	public static Shape  getShape(String shapeId){
		Shape cache = shapeMap.get(shapeId);
		return (Shape) cache.clone();
	}
	
	
	public static void loadcae(){
		Circle c1 = new Circle();
		c1.setId("10");
		shapeMap.put(c1.getId(), c1);
		
		Rectangle  Rec = new Rectangle();
		Rec.setId("11");
		shapeMap.put(Rec.getId(), Rec);
		
		Square  sq = new Square();
		sq.setId("12");
		shapeMap.put(sq.getId(), sq);
		
	}

	
	public static void main(String[] args) {
		ShapeCache.loadcae();
		
		Shape s1 = ShapeCache.getShape("1");
		System.out.println("type:"+s1.getType());
		
		Shape s2 = ShapeCache.getShape("2");
		System.out.println("type:"+s2.getType());
		
		
		Shape s3 = ShapeCache.getShape("3");
		System.out.println("type:"+s3.getType());
		
		
	}
	
	
}
